import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCityStore = defineStore('city', () => {

  const getDefaultCity = () => {
    let defaultCity = ref("武汉");
    let city = localStorage.getItem("city");
    if (city) {
      defaultCity.value = city;
    }
    return defaultCity;
  }

  const city = getDefaultCity();
  /* 改变city的方法 */
  const changeCity = (val) => {
    city.value = val;
    /* 设置localStorage */
    localStorage.setItem("city", val);
  }
  return { city, changeCity }
})
